﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace OMSReportViewer
{
    public static class Logger
    {
        private static string m_strLogPath = PathLocations.Log;

        public static void LogInformation(string msg)
        {
            StreamWriter writer = null;
            string strFulleMsg = "\n\nInfo: " + msg + "\n\n";
            Console.WriteLine(strFulleMsg);
            try
            {
                new StreamWriter(m_strLogPath);
                writer.WriteLine(strFulleMsg);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occured while trying to log.\n\nEXCEPTION: " + ex.Message + "\n\n");
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }

        public static void LogException(Exception ex)
        {
            StreamWriter writer = null;
            string strFulleMsg = "Error occured while trying to log.\n\nEXCEPTION: " + ex.Message + "\n\n" + ex.StackTrace;
            Console.WriteLine(strFulleMsg);
            try
            {
                new StreamWriter(m_strLogPath);
                writer.WriteLine(strFulleMsg);
            }
            catch (Exception innerEx)
            {
                Console.WriteLine(strFulleMsg);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
    }
}